#include <subControllItem.h>
#include <postManager.h>

namespace View {

  static void
  SubControllItemAnimationFinished (GooCanvasItemModel *item,
				    gboolean            stopped,
				    gpointer            user_data)
  {
    Controller::PostManager *poster = Controller::PostManager::GetPostManager();
    poster->SetBroadcastType(Controller::BROADCAST_TYPE_SUBITEM_ANIMATE_STOP);
    poster->SendBroadcast();
  }

  SubControllItem::SubControllItem(GooCanvasItem *parent)
    :root(goo_canvas_group_new(parent,NULL))
  {
    ViewConf *conf = ViewConf::GetViewConf();
    coordinatesX = - conf->GetDoubleData("mainWindowLength");
    coordinatesY = 0;// - conf->GetDoubleData("mainWindowHeigth");
    g_object_set(root,
		 "x", coordinatesX,
		 "y", coordinatesY,
		 NULL);
    g_signal_connect(G_OBJECT(root),"animation_finished",
		     G_CALLBACK(SubControllItemAnimationFinished),NULL);
  }

  SubControllItem::~SubControllItem()
  {
    goo_canvas_item_remove(root);
  }
    
  bool SubControllItem::RunTo(double xOffset, double yOffset)
  {
    coordinatesX = xOffset - coordinatesX;
    coordinatesY = yOffset - coordinatesY;
    goo_canvas_item_animate(root,coordinatesX,coordinatesY,
			    1,0.0,FALSE,100,10,
			    GOO_CANVAS_ANIMATE_FREEZE);
    coordinatesX = xOffset;
    coordinatesY = yOffset;
    return true;
  }


}
